﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ERPStudio;
using System.Data.SqlClient;

namespace ResUma
{
    public partial class AngajatiGarziFrm : FrmRezumat 
    {
        public AngajatiGarziFrm(ModuleClass mc): base(mc)
        {
            InitializeComponent();
            garziESRPDataSet.AngajatiGarzi.CodUnitateColumn.DefaultValue = ModuleInfo.CodUnitate;
        }

      
        private void AngajatiGarziFrm_Load(object sender, EventArgs e)
        {
            SqlConnection con = DeschideConexiune(workConnString);
            this.resUmaSetupTableAdapter.Connection = con;
            this.resUmaSetupTableAdapter.Fill(this.garziESRPDataSet.ResUmaSetup, ModuleInfo.CodUnitate);
            this.angajatiGarziTableAdapter.Connection = con;
            this.angajatiGarziTableAdapter.Fill(this.garziESRPDataSet.AngajatiGarzi,ModuleInfo.CodUnitate);
            this.angajatiSalarizareTableAdapter.Connection = con;
            this.angajatiSalarizareTableAdapter.Fill(this.garziESRPDataSet.AngajatiSalarizare);
            this.persoaneTableAdapter.Connection = con;
            this.persoaneTableAdapter.Fill(this.garziESRPDataSet.Persoane,ModuleInfo.CodUnitate);
            InchideConexiune(con);

            #region valori implicite pentru luna si an
            if (resUmaSetupBindingSource.Count == 0)
            {
                MessageBoxFrm mbt = new MessageBoxFrm("Eroare validare", "Modulul nu a fost configurat inca!", String.Empty, MessageBoxFrm.ImaginiMB.StopIcon, null);
                mbt.AddButton("Ieşire", 70, mbt.MessageBoxFrm_Click_Yes);
                mbt.ShowDialog();
                Close();
                return;
            }
            GarziESRPDataSet.ResUmaSetupRow cfgRow = ((DataRowView)resUmaSetupBindingSource.Current).Row as GarziESRPDataSet.ResUmaSetupRow;
            garziESRPDataSet.AngajatiGarzi.LunaColumn.DefaultValue = cfgRow.LunaCurenta;
            garziESRPDataSet.AngajatiGarzi.AnulColumn.DefaultValue = cfgRow.AnulCurent; 
            #endregion


            #region valoare implicita pentru IDPersoana
            if (persoaneBindingSource.Count == 0)
            {
                MessageBoxFrm mbt = new MessageBoxFrm("Eroare validare", "Nu exista pesoane in baza de date!", String.Empty, MessageBoxFrm.ImaginiMB.StopIcon, null);
                mbt.AddButton("Ieşire", 70, mbt.MessageBoxFrm_Click_Yes);
                mbt.ShowDialog();
                Close();
                return;
            }

            GarziESRPDataSet.PersoaneRow pRow = ((DataRowView)persoaneBindingSource.Current).Row as GarziESRPDataSet.PersoaneRow;
            garziESRPDataSet.AngajatiGarzi.IDPersoanaColumn.DefaultValue = pRow.IdPersoana; 
            #endregion


            AddBindingSource(fKAngajatiGarziAngajatiSalarizareBindingSource);
            AddTableAdaptor(angajatiGarziTableAdapter.Adapter);

        }

        override public void Salvare(object sender, EventArgs args)
        {
            base.Salvare(sender, args);
            if (EroareSalvare)
                return;

            //SetCurentUnit(ModuleInfo.CodUnitate);
        }

        private void angajatiGarziDGV_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        {
            int i = 0;
            i++;
        }

        private void numePrenumeCB_SelectedIndexChanged(object sender, EventArgs e)
        {
            #region valoare implicita pentru IDPersoana
            if (persoaneBindingSource.Count == 0)
            {
                MessageBoxFrm mbt = new MessageBoxFrm("Eroare validare", "Nu exista pesoane in baza de date!", String.Empty, MessageBoxFrm.ImaginiMB.StopIcon, null);
                mbt.AddButton("Ieşire", 70, mbt.MessageBoxFrm_Click_Yes);
                mbt.ShowDialog();
                Close();
                return;
            }
            GarziESRPDataSet.PersoaneRow pRow = ((DataRowView)persoaneBindingSource.Current).Row as GarziESRPDataSet.PersoaneRow;
            garziESRPDataSet.AngajatiGarzi.IDPersoanaColumn.DefaultValue = pRow.IdPersoana;
            #endregion
        }
    }
}
